﻿namespace KeRui.TemplateMaker
{
    using KeRui.BLL;
    using KeRui.Common;
    using KeRui.Model;
    using iPortal.TemplateEngine;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;

    public class Publish
    {
        private static string ConvertKeywords(string source)
        {
            string[] strArray = source.Split(" ".ToCharArray());
            return string.Join(",", strArray);
        }

        private static void GeneratePath(string path)
        {
            string[] strArray = path.Split(@"\".ToCharArray());
            string str = strArray[0];
            for (int i = 1; i < strArray.Length; i++)
            {
                str = str + @"\" + strArray[i];
                if (!Directory.Exists(str))
                {
                    Directory.CreateDirectory(str);
                }
            }
        }

        private string getDefault(string Path)
        {
            if ((Path == "") || (Path == null))
            {
                Path = "/Template/_ad/images/Nopic.gif";
            }
            return Path;
        }

        private string getHref(KeRui.Model.Ad modelAd)
        {
            string str = string.Concat(new object[] { "/AdHandle.aspx?ID=", modelAd.AdID, "&url=", modelAd.CurUrl });
            if ((modelAd.CurUrl.Trim() == "#") || (modelAd.CurUrl.Trim() == ""))
            {
                str = "#";
            }
            return str;
        }

        public static string GetItemUrlValue(int contentID, int nodeID)
        {
            string str;
            KeRui.Model.CmsNode modelByCache;
            KeRui.BLL.CmsNode node = new KeRui.BLL.CmsNode();
            KeRui.BLL.CmsSite site = new KeRui.BLL.CmsSite();
            if (nodeID != 0)
            {
                modelByCache = node.GetModelByCache(nodeID);
                str = site.GetModelByCache(modelByCache.SiteID).SiteUrl + "/" + modelByCache.NodePath + "/";
            }
            else
            {
                KeRui.BLL.CmsContent content = new KeRui.BLL.CmsContent();
                modelByCache = node.GetModelByCache(content.GetModel(contentID).NodeID);
                str = site.GetModelByCache(modelByCache.SiteID).SiteUrl + "/" + modelByCache.NodePath + "/";
            }
            return (str + contentID + ".shtml");
        }

        public string PublishAd(int AdID, int type)
        {
            Exception exception;
            KeRui.BLL.CmsSite site;
            string str6;
            string str7;
            if (AdID == -1)
            {
                return "没有获得AdID。";
            }
            KeRui.BLL.Ad ad = new KeRui.BLL.Ad();
            KeRui.BLL.SellerAD rad = new KeRui.BLL.SellerAD();
            ad.UpdateForSellerAd(AdID);
            KeRui.Model.Ad model = ad.GetModel(AdID);
            if (model == null)
            {
                return (AdID + "广告已经被删除。");
            }
            string path = "";
            try
            {
                if (model.CurID > 0)
                {
                    path = model.CurAdText;
                }
                else
                {
                    path = model.DefaultAdText;
                }
            }
            catch (Exception exception1)
            {
                exception = exception1;
                return exception.Message;
            }
            string str2 = "";
            if (!model.IsUsing)
            {
                site = new KeRui.BLL.CmsSite();
                str6 = site.GetModelByCache(model.SiteID).TemplateDir + @"\_ad";
                str7 = string.Concat(new object[] { str6, @"\", AdID, ".shtml" });
                GeneratePath(str6);
                StreamWriter writer = new StreamWriter(str7, false, Encoding.GetEncoding("gb2312"));
                writer.Flush();
                writer.Close();
                writer.Dispose();
            }
            else
            {
                if (path == "")
                {
                    return (AdID + "广告没有内容。");
                }
                string str3 = "";
                string str4 = "";
                if (model.AdWidth > 800)
                {
                    str3 = "<div class='bot'>";
                    str4 = "</div>";
                }
                site = new KeRui.BLL.CmsSite();
                string siteUrl = site.GetModelByCache(model.SiteID).SiteUrl;
                switch (model.AdType)
                {
                    case 1:
                        str2 = "<a href='" + siteUrl + this.getHref(model) + "' target='_blank'>" + path + "</a>\r\n";
                        break;

                    case 2:
                        str2 = string.Concat(new object[] { str3, "<a href='", siteUrl, this.getHref(model), "' target='_blank'><image src='", siteUrl, this.getDefault(path), "' style='width:", model.AdWidth, "px;height:", model.AdHight, "px;' border=0/></a>\r\n", str4, "" });
                        break;

                    case 3:
                        str2 = string.Concat(new object[] { 
                            str3, "<button onclick='window.open(\\\"", siteUrl, this.getHref(model), "\\\")' style='border:0px;width:", model.AdWidth, "px;height:", model.AdHight, "px;background:#FFFFFF' ><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='", model.AdWidth, "' height='", model.AdHight, "'><param name='movie' value='", siteUrl, path, "' /><param name='quality' value='high' /><param name='wmode' value='opaque' /><embed src='", 
                            siteUrl, path, "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='", model.AdWidth, "' height='", model.AdHight, "'></embed></object></button>", str4, "\r\n"
                         });
                        break;
                }
                try
                {
                    TemplateDocument document;
                    if (type == 1)
                    {
                        document = new TemplateDocument(HttpContext.Current.Server.MapPath("/Template/_ad/template/ad.shtml"), Encoding.GetEncoding("utf-8"));
                        str6 = HttpContext.Current.Server.MapPath("/Template/_ad");
                    }
                    else
                    {
                        document = new TemplateDocument(site.GetModelByCache(model.SiteID).TemplateDir + @"\_ad\template\ad.shtml", Encoding.GetEncoding("utf-8"));
                        str6 = site.GetModelByCache(model.SiteID).TemplateDir + @"\_ad";
                    }
                    document.Variables.SetValue("content", str2);
                    str7 = string.Concat(new object[] { str6, @"\", AdID, ".shtml" });
                    GeneratePath(str6);
                    document.RenderTo(str7, Encoding.GetEncoding("utf-8"));
                    document.Variables.SetValue("content", "document.write(\"" + str2.Replace("\r\n", "") + "\")\r\n");
                    str7 = string.Concat(new object[] { str6, @"\", AdID, ".js" });
                    GeneratePath(str6);
                    document.RenderTo(str7, Encoding.GetEncoding("utf-8"));
                }
                catch (Exception exception2)
                {
                    exception = exception2;
                    return exception.Message;
                }
            }
            return "";
        }

        public int PublishContent(int contentID)
        {
            string[] strArray;
            KeRui.BLL.CmsContent content = new KeRui.BLL.CmsContent();
            KeRui.BLL.CmsNode node = new KeRui.BLL.CmsNode();
            KeRui.BLL.CmsSite site = new KeRui.BLL.CmsSite();
            DataRow row = content.GetModelDetailsByContentID(contentID).Tables[0].Rows[0];
            string input = row["Content"].ToString();
            Regex regex = new Regex("<div\\s+style=\"page-break-after:\\s+always\">\\s+<span\\s+style=\"display: none\">[^<]*?</span></div>");
            if (regex.Match(input).Success)
            {
                input = regex.Replace(input, "{$:content.pagebreak}");
                string[] separator = new string[] { "{$:content.pagebreak}" };
                strArray = input.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                strArray = new string[] { input };
            }
            for (int i = 0; i < strArray.Length; i++)
            {
                int num4;
                string str8;
                row["Content"] = strArray[i];
                if (strArray.Length > 1)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append("<div class=\"page\"><span><strong>共" + strArray.Length + "篇</strong></span>");
                    for (int j = 0; j < strArray.Length; j++)
                    {
                        if (j == 0)
                        {
                            if (j == i)
                            {
                                builder.AppendFormat("<a class='current'>{0}</a>", j + 1);
                            }
                            else
                            {
                                builder.AppendFormat("<a href='{0}'>{1}</a>", row["ContentID"] + ".shtml", j + 1);
                            }
                        }
                        else if (j > (strArray.Length - 3))
                        {
                            if (j == i)
                            {
                                builder.AppendFormat("<a class='current'>{0}</a>", j + 1);
                            }
                            else
                            {
                                builder.AppendFormat("<a href='{0}'>{1}</a>", string.Concat(new object[] { row["ContentID"], "_", j + 1, ".shtml" }), j + 1);
                            }
                        }
                        else if ((j >= (i - 2)) && (j <= (i + 2)))
                        {
                            if (j == i)
                            {
                                builder.AppendFormat("<a class='current'>{0}</a>", j + 1);
                            }
                            else
                            {
                                builder.AppendFormat("<a href='{0}'>{1}</a>", string.Concat(new object[] { row["ContentID"], "_", j + 1, ".shtml" }), j + 1);
                            }
                        }
                        else if ((j == (i - 3)) || (j == (i + 3)))
                        {
                            builder.AppendFormat("<a href='{0}'>...</a>", string.Concat(new object[] { row["ContentID"], "_", j + 1, ".shtml" }));
                        }
                    }
                    if ((i != (strArray.Length - 1)) && (strArray.Length > 1))
                    {
                        builder.AppendFormat("<a href='{0}'>下一页</a>", string.Concat(new object[] { row["ContentID"], "_", i + 2, ".shtml" }));
                        builder.AppendFormat("<a href='{0}'>尾页</a>", string.Concat(new object[] { row["ContentID"], "_", strArray.Length, ".shtml" }));
                    }
                    builder.Append("</div>");
                    row["Content"] = row["Content"] + builder.ToString();
                }
                int nodeID = Convert.ToInt32(row["NodeID"]);
                TemplateDocument templateDocument = new TemplateDocument(string.Concat(new object[] { site.GetModelByCache(node.GetModelByCache(nodeID).SiteID).TemplateDir, @"\", site.GetModelByCache(node.GetModelByCache(nodeID).SiteID).TemplateFolder, @"\", row["TemplateFile"] }), Encoding.GetEncoding("utf-8"));
                templateDocument.Variables.SetValue("content", row);
                StringBuilder builder2 = new StringBuilder();
                if (node.GetModelByCache(content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID).ParentPath == "0")
                {
                    builder2.AppendFormat("<li><a href='{0}' class='ContentPageLocation'>{1}</a></li>", "/", "首页");
                }
                else
                {
                    string parentPath = node.GetModelByCache(content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID).ParentPath;
                    if (parentPath.Length > 0)
                    {
                        parentPath = parentPath + "," + content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID;
                    }
                    else
                    {
                        parentPath = content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID.ToString();
                    }
                    string siteUrl = site.GetModelByCache(node.GetModelByCache(content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID).SiteID).SiteUrl;
                    num4 = 0;
                    while (num4 < parentPath.Split(",".ToCharArray()).Length)
                    {
                        KeRui.Model.CmsNode modelByCache;
                        if (num4 != (parentPath.Split(",".ToCharArray()).Length - 1))
                        {
                            try
                            {
                                modelByCache = node.GetModelByCache(Convert.ToInt32(parentPath.Split(",".ToCharArray())[num4]));
                                if (modelByCache.ShowOnMenu)
                                {
                                    builder2.AppendFormat("<li><a href='{0}' class='c327CB6'>{1}</a>>></li>", siteUrl + "/" + modelByCache.NodePath, modelByCache.NodeName);
                                }
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            modelByCache = node.GetModelByCache(Convert.ToInt32(parentPath.Split(",".ToCharArray())[num4]));
                            if (modelByCache.ShowOnMenu)
                            {
                                builder2.AppendFormat("<li><a href='{0}' class='c327CB6'>{1}</a></li>", siteUrl + "/" + modelByCache.NodePath, modelByCache.NodeName);
                            }
                        }
                        num4++;
                    }
                }
                templateDocument.Variables.SetExpValue("content.nav", builder2.ToString());
                if (!string.IsNullOrEmpty(row["Keyword"].ToString()))
                {
                    templateDocument.Variables.SetExpValue("content.commakeywords", ConvertKeywords(row["Keyword"].ToString()));
                }
                string[] strArray3 = row["Keyword"].ToString().Split(" ".ToCharArray());
                StringBuilder builder3 = new StringBuilder();
                builder3.Append(" AND cc.ContentID in (SELECT DataID FROM dbo.SearchData WHERE Tag in (");
                num4 = 0;
                while (num4 < strArray3.Length)
                {
                    string[] strArray4 = Utils.SplitString(SegmentHelper.GetKeyword(strArray3[num4]), " ");
                    if (num4 != 0)
                    {
                        builder3.Append(",");
                    }
                    if (strArray4.Length > 1)
                    {
                        int index = 0;
                        while (index < strArray4.Length)
                        {
                            if (index != 0)
                            {
                                builder3.Append(",");
                            }
                            builder3.Append("'" + Utils.SqlStringFormat(strArray4[index], 1) + "' ");
                            num4++;
                        }
                    }
                    else
                    {
                        builder3.Append("'" + Utils.SqlStringFormat(strArray3[num4], 1) + "' ");
                    }
                    num4++;
                }
                builder3.Append("))");
                DataTable table = content.GetCmsContentDetailsByNodeID(nodeID, "TOP 10", builder3.ToString(), "");
                StringBuilder builder4 = new StringBuilder();
                builder4.AppendFormat("<ul>", new object[0]);
                foreach (DataRow row2 in table.Rows)
                {
                    builder4.AppendFormat("<li><a href=\"{0}\">\x00b7{1}</a></li>", GetItemUrlValue(Convert.ToInt32(row2["ContentID"]), Convert.ToInt32(row2["NodeID"])), row2["Title"]);
                }
                builder4.AppendFormat("</ul>", new object[0]);
                templateDocument.Variables.SetExpValue("content.keywordnews", builder4.ToString());
                StringBuilder builder5 = new StringBuilder();
                for (num4 = 0; num4 < strArray3.Length; num4++)
                {
                    builder5.AppendFormat("<a href='{0}' target='_blank'>{1}</a>", "/aspx/Search.aspx?q=" + Utils.UrlEncode(strArray3[num4], "utf-8"), strArray3[num4]);
                }
                templateDocument.Variables.SetExpValue("content.keywordlinks", builder5.ToString());
                int num6 = Convert.ToInt32(row["PrevID"]);
                KeRui.Model.CmsContent model = content.GetModel(num6);
                if (model == null)
                {
                    templateDocument.Variables.SetExpValue("content.pretitle", "没有文章了");
                    templateDocument.Variables.SetExpValue("content.preurl", "#");
                }
                else
                {
                    templateDocument.Variables.SetExpValue("content.pretitle", model.Title);
                    templateDocument.Variables.SetExpValue("content.preurl", GetItemUrlValue(model.ContentID, model.NodeID));
                }
                int num7 = Convert.ToInt32(row["NextID"]);
                KeRui.Model.CmsContent content3 = content.GetModel(num7);
                if (content3 == null)
                {
                    templateDocument.Variables.SetExpValue("content.nexttitle", "没有文章了");
                    templateDocument.Variables.SetExpValue("content.nexturl", "#");
                }
                else
                {
                    templateDocument.Variables.SetExpValue("content.nexttitle", content3.Title);
                    templateDocument.Variables.SetExpValue("content.nexturl", GetItemUrlValue(content3.ContentID, content3.NodeID));
                }
                ElementCollection<Template> childTemplatesByName = templateDocument.GetChildTemplatesByName("relativenews");
                foreach (Template template in childTemplatesByName)
                {
                    DateTime time4;
                    DataTable table2;
                    string str6 = template.Attributes.GetValue("time");
                    int top = Convert.ToInt32(template.Attributes.GetValue("num"));
                    string dateRange = string.Empty;
                    DateTime now = DateTime.Now;
                    string str9 = str6;
                    if (str9 != null)
                    {
                        if (!(str9 == "week"))
                        {
                            if (str9 == "month")
                            {
                                goto Label_0C0B;
                            }
                        }
                        else
                        {
                            DateTime time2 = now.AddDays((double) (1 - Convert.ToInt32(now.DayOfWeek.ToString("d"))));
                            DateTime time3 = time2.AddDays(6.0);
                            dateRange = string.Concat(new object[] { " AND createtime between '", time2, "' and '", time3, "'" });
                        }
                    }
                    goto Label_0C7E;
                Label_0C0B:
                    time4 = now.AddDays((double) (1 - now.Day));
                    DateTime time5 = time4.AddMonths(1).AddDays(-1.0);
                    dateRange = string.Concat(new object[] { " AND createtime between '", time4, "' and '", time5, "'" });
                Label_0C7E:
                    table2 = content.GetCmsContentRelativeNews(nodeID, template.Attributes.GetValue("type"), top, dateRange);
                    template.Variables.SetValue("newsdata", table2);
                    Tag childTagById = template.GetChildTagById("newslist");
                    if ((childTagById != null) && (childTagById is ForEachTag))
                    {
                        childTagById.BeforeRender += new CancelEventHandler(Publish.Tag_BeforeRender);
                    }
                }
                ResolveTag.ResolveForeach(templateDocument);
                ResolveTag.ResolveTemplate(templateDocument);
                if (i == 0)
                {
                    str8 = string.Concat(new object[] { node.GetModelByCache(nodeID).NodeDir, @"\", row["ContentID"], ".shtml" });
                    GeneratePath(node.GetModelByCache(nodeID).NodeDir);
                    templateDocument.RenderTo(str8, Encoding.GetEncoding("utf-8"));
                }
                else
                {
                    str8 = string.Concat(new object[] { node.GetModelByCache(nodeID).NodeDir, @"\", row["ContentID"], "_", i + 1, ".shtml" });
                    GeneratePath(node.GetModelByCache(nodeID).NodeDir);
                    templateDocument.RenderTo(str8, Encoding.GetEncoding("utf-8"));
                }
            }
            return 1;
        }

        public int PublishContent(string nodeIDCollection, int type)
        {
            int num = 0;
            KeRui.BLL.CmsContent content = new KeRui.BLL.CmsContent();
            KeRui.BLL.CmsNode node = new KeRui.BLL.CmsNode();
            KeRui.BLL.CmsSite site = new KeRui.BLL.CmsSite();
            foreach (string str in nodeIDCollection.Split(",".ToCharArray()))
            {
                int nodeID = Convert.ToInt16(str);
                if (node.GetModelByCache(nodeID).NodeType == 2)
                {
                    num++;
                }
                else
                {
                    DataTable table = content.GetCmsContentDetailsByNodeID(nodeID, "", "", "");
                    string templateFolder = site.GetModelByCache(node.GetModelByCache(nodeID).SiteID).TemplateFolder;
                    if (table.Rows.Count > 0)
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            TemplateDocument document;
                            string[] strArray;
                            if (type == 1)
                            {
                                document = new TemplateDocument(HttpContext.Current.Server.MapPath(string.Concat(new object[] { "/Template/", templateFolder, "/", row["TemplateFile"] })), Encoding.GetEncoding("utf-8"));
                            }
                            else
                            {
                                document = new TemplateDocument(string.Concat(new object[] { site.GetModelByCache(node.GetModelByCache(nodeID).SiteID).TemplateDir, @"\", site.GetModelByCache(node.GetModelByCache(nodeID).SiteID).SiteKey, @"\", row["TemplateFile"] }), Encoding.GetEncoding("utf-8"));
                            }
                            string input = row["Content"].ToString();
                            Regex regex = new Regex("<div\\s+style=\"page-break-after:\\s+always\">\\s+<span\\s+style=\"display: none\">&nbsp;</span></div>");
                            if (regex.Match(input).Success)
                            {
                                input = regex.Replace(input, "{$:content.pagebreak}");
                                string[] separator = new string[] { "{$:content.pagebreak}" };
                                strArray = input.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                            }
                            else
                            {
                                strArray = new string[] { input };
                            }
                            for (int i = 0; i < strArray.Length; i++)
                            {
                                int num5;
                                string str10;
                                row["Content"] = strArray[i];
                                if (strArray.Length > 1)
                                {
                                    StringBuilder builder = new StringBuilder();
                                    builder.Append("<div class=\"page\"><span><strong>共" + strArray.Length + "页</strong></span>");
                                    for (int j = 0; j < strArray.Length; j++)
                                    {
                                        if (j == 0)
                                        {
                                            if (j == i)
                                            {
                                                builder.AppendFormat("<a class='current'>{0}</a>", j + 1);
                                            }
                                            else
                                            {
                                                builder.AppendFormat("<a href='{0}'>{1}</a>", row["ContentID"] + ".shtml", j + 1);
                                            }
                                        }
                                        else if (j > (strArray.Length - 3))
                                        {
                                            if (j == i)
                                            {
                                                builder.AppendFormat("<a class='current'>{0}</a>", j + 1);
                                            }
                                            else
                                            {
                                                builder.AppendFormat("<a href='{0}'>{1}</a>", string.Concat(new object[] { row["ContentID"], "_", j + 1, ".shtml" }), j + 1);
                                            }
                                        }
                                        else if ((j >= (i - 2)) && (j <= (i + 2)))
                                        {
                                            if (j == i)
                                            {
                                                builder.AppendFormat("<a class='current'>{0}</a>", j + 1);
                                            }
                                            else
                                            {
                                                builder.AppendFormat("<a href='{0}'>{1}</a>", string.Concat(new object[] { row["ContentID"], "_", j + 1, ".shtml" }), j + 1);
                                            }
                                        }
                                        else if ((j == (i - 3)) || (j == (i + 3)))
                                        {
                                            builder.AppendFormat("<a href='{0}'>...</a>", string.Concat(new object[] { row["ContentID"], "_", j + 1, ".shtml" }));
                                        }
                                    }
                                    if ((i != (strArray.Length - 1)) && (strArray.Length > 1))
                                    {
                                        builder.AppendFormat("<a href='{0}'>下一页</a>", string.Concat(new object[] { row["ContentID"], "_", i + 2, ".shtml" }));
                                        builder.AppendFormat("<a href='{0}'>尾页</a>", string.Concat(new object[] { row["ContentID"], "_", strArray.Length, ".shtml" }));
                                    }
                                    builder.Append("</div>");
                                    row["Content"] = row["Content"] + builder.ToString();
                                }
                                document.Variables.SetValue("content", row);
                                if (!string.IsNullOrEmpty(row["Keyword"].ToString()))
                                {
                                    string[] strArray3 = row["Keyword"].ToString().Split(" ".ToCharArray());
                                    StringBuilder builder2 = new StringBuilder();
                                    builder2.Append(" AND cc.ContentID in (SELECT DataID FROM dbo.SearchData WHERE Tag in (");
                                    num5 = 0;
                                    while (num5 < strArray3.Length)
                                    {
                                        string[] strArray4 = Utils.SplitString(SegmentHelper.GetKeyword(strArray3[num5]), " ");
                                        if (num5 != 0)
                                        {
                                            builder2.Append(",");
                                        }
                                        if (strArray4.Length > 1)
                                        {
                                            int index = 0;
                                            while (index < strArray4.Length)
                                            {
                                                if (index != 0)
                                                {
                                                    builder2.Append(",");
                                                }
                                                builder2.Append("'" + Utils.SqlStringFormat(strArray4[index], 1) + "' ");
                                                num5++;
                                            }
                                        }
                                        else
                                        {
                                            builder2.Append("'" + Utils.SqlStringFormat(strArray3[num5], 1) + "' ");
                                        }
                                        num5++;
                                    }
                                    builder2.Append("))");
                                    DataTable table2 = content.GetCmsContentDetailsByNodeID(nodeID, "TOP 10", builder2.ToString(), "");
                                    StringBuilder builder3 = new StringBuilder();
                                    builder3.AppendFormat("<ul>", new object[0]);
                                    foreach (DataRow row2 in table2.Rows)
                                    {
                                        builder3.AppendFormat("<li><a href=\"{0}\">\x00b7{1}</a></li>", GetItemUrlValue(Convert.ToInt32(row2["ContentID"]), Convert.ToInt32(row2["NodeID"])), row2["Title"]);
                                    }
                                    builder3.AppendFormat("</ul>", new object[0]);
                                    document.Variables.SetExpValue("content.keywordnews", builder3.ToString());
                                    StringBuilder builder4 = new StringBuilder();
                                    num5 = 0;
                                    while (num5 < strArray3.Length)
                                    {
                                        builder4.AppendFormat("<a href='{0}' target='_blank'>{1}</a>", "/aspx/Search.aspx?q=" + Utils.UrlEncode(strArray3[num5], "utf-8"), strArray3[num5]);
                                        num5++;
                                    }
                                    document.Variables.SetExpValue("content.keywordlinks", builder4.ToString());
                                }
                                if (!string.IsNullOrEmpty(row["Keyword"].ToString()))
                                {
                                    document.Variables.SetExpValue("content.commakeywords", ConvertKeywords(row["Keyword"].ToString()));
                                }
                                string str6 = node.GetModelByCache(content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID).ParentPath + "," + content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID;
                                StringBuilder builder5 = new StringBuilder();
                                string siteUrl = site.GetModelByCache(node.GetModelByCache(content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID).SiteID).SiteUrl;
                                for (num5 = 0; num5 < str6.Split(",".ToCharArray()).Length; num5++)
                                {
                                    KeRui.Model.CmsNode modelByCache;
                                    if (num5 != (str6.Split(",".ToCharArray()).Length - 1))
                                    {
                                        modelByCache = node.GetModelByCache(Convert.ToInt32(str6.Split(",".ToCharArray())[num5]));
                                        if (modelByCache.ShowOnMenu)
                                        {
                                            builder5.AppendFormat("<li><a href='{0}' class='c327CB6 '>{1}</a>>></li>", siteUrl + "/" + modelByCache.NodePath, modelByCache.NodeName);
                                        }
                                    }
                                    else
                                    {
                                        modelByCache = node.GetModelByCache(Convert.ToInt32(str6.Split(",".ToCharArray())[num5]));
                                        if (modelByCache.ShowOnMenu)
                                        {
                                            builder5.AppendFormat("<li><a href='{0}' class='c327CB6 '>{1}</a></li>", siteUrl + "/" + modelByCache.NodePath, modelByCache.NodeName);
                                        }
                                    }
                                }
                                document.Variables.SetExpValue("content.nav", builder5.ToString());
                                if (row["PrevID"].ToString() != "0")
                                {
                                    int contentID = Convert.ToInt32(row["PrevID"]);
                                    KeRui.Model.CmsContent content2 = content.GetModelByCache(contentID);
                                    if (content2 == null)
                                    {
                                        document.Variables.SetExpValue("content.pretitle", "没有文章了");
                                        document.Variables.SetExpValue("content.preurl", "#");
                                    }
                                    else
                                    {
                                        document.Variables.SetExpValue("content.pretitle", content2.Title);
                                        document.Variables.SetExpValue("content.preurl", GetItemUrlValue(content2.ContentID, content2.NodeID));
                                    }
                                }
                                if (row["NextID"].ToString() != "0")
                                {
                                    int num8 = Convert.ToInt32(row["NextID"]);
                                    KeRui.Model.CmsContent content3 = content.GetModelByCache(num8);
                                    if (content3 == null)
                                    {
                                        document.Variables.SetExpValue("content.nexttitle", "没有文章了");
                                        document.Variables.SetExpValue("content.nexturl", "#");
                                    }
                                    else
                                    {
                                        document.Variables.SetExpValue("content.nexttitle", content3.Title);
                                        document.Variables.SetExpValue("content.nexturl", GetItemUrlValue(content3.ContentID, content3.NodeID));
                                    }
                                }
                                ElementCollection<Template> childTemplatesByName = document.GetChildTemplatesByName("relativenews");
                                foreach (Template template in childTemplatesByName)
                                {
                                    DateTime time4;
                                    DataTable table3;
                                    string str8 = template.Attributes.GetValue("time");
                                    int top = Convert.ToInt32(template.Attributes.GetValue("num"));
                                    string dateRange = string.Empty;
                                    DateTime now = DateTime.Now;
                                    string str11 = str8;
                                    if (str11 != null)
                                    {
                                        if (!(str11 == "week"))
                                        {
                                            if (str11 == "month")
                                            {
                                                goto Label_0CE9;
                                            }
                                        }
                                        else
                                        {
                                            DateTime time2 = now.AddDays((double) (1 - Convert.ToInt32(now.DayOfWeek.ToString("d"))));
                                            DateTime time3 = time2.AddDays(6.0);
                                            dateRange = string.Concat(new object[] { " AND createtime between '", time2, "' and '", time3, "'" });
                                        }
                                    }
                                    goto Label_0D5C;
                                Label_0CE9:
                                    time4 = now.AddDays((double) (1 - now.Day));
                                    DateTime time5 = time4.AddMonths(1).AddDays(-1.0);
                                    dateRange = string.Concat(new object[] { " AND createtime between '", time4, "' and '", time5, "'" });
                                Label_0D5C:
                                    table3 = content.GetCmsContentRelativeNews(nodeID, template.Attributes.GetValue("type"), top, dateRange);
                                    template.Variables.SetValue("newsdata", table3);
                                    Tag childTagById = template.GetChildTagById("newslist");
                                    if ((childTagById != null) && (childTagById is ForEachTag))
                                    {
                                        childTagById.BeforeRender += new CancelEventHandler(Publish.Tag_BeforeRender);
                                    }
                                }
                                ResolveTag.ResolveForeach(document);
                                ResolveTag.ResolveTemplate(document);
                                if (i == 0)
                                {
                                    str10 = string.Concat(new object[] { node.GetModelByCache(nodeID).NodeDir, @"\", row["ContentID"], ".shtml" });
                                    GeneratePath(node.GetModelByCache(nodeID).NodeDir);
                                    document.RenderTo(str10, Encoding.GetEncoding("utf-8"));
                                }
                                else
                                {
                                    str10 = string.Concat(new object[] { node.GetModelByCache(nodeID).NodeDir, @"\", row["ContentID"], "_", i + 1, ".shtml" });
                                    GeneratePath(node.GetModelByCache(nodeID).NodeDir);
                                    document.RenderTo(str10, Encoding.GetEncoding("utf-8"));
                                }
                            }
                        }
                    }
                    num += table.Rows.Count;
                }
            }
            return num;
        }

        public int PublishContent(string nodeIDCollection, int type, string conditions)
        {
            int num = 0;
            KeRui.BLL.CmsContent content = new KeRui.BLL.CmsContent();
            KeRui.BLL.CmsNode node = new KeRui.BLL.CmsNode();
            KeRui.BLL.CmsSite site = new KeRui.BLL.CmsSite();
            foreach (string str in nodeIDCollection.Split(",".ToCharArray()))
            {
                int nodeID = Convert.ToInt16(str);
                if (node.GetModelByCache(nodeID).NodeType == 2)
                {
                    num++;
                }
                else
                {
                    DataTable table = content.GetCmsContentDetailsByNodeID(nodeID, "", conditions, "");
                    string templateFolder = site.GetModelByCache(node.GetModelByCache(nodeID).SiteID).TemplateFolder;
                    if (table.Rows.Count > 0)
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            TemplateDocument document;
                            string[] strArray;
                            if (type == 1)
                            {
                                document = new TemplateDocument(HttpContext.Current.Server.MapPath(string.Concat(new object[] { "/Template/", templateFolder, "/", row["TemplateFile"] })), Encoding.GetEncoding("utf-8"));
                            }
                            else
                            {
                                document = new TemplateDocument(string.Concat(new object[] { site.GetModelByCache(node.GetModelByCache(nodeID).SiteID).TemplateDir, @"\", site.GetModelByCache(node.GetModelByCache(nodeID).SiteID).SiteKey, @"\", row["TemplateFile"] }), Encoding.GetEncoding("utf-8"));
                            }
                            string input = row["Content"].ToString();
                            Regex regex = new Regex("<div\\s+style=\"page-break-after:\\s+always\">\\s+<span\\s+style=\"display: none\">&nbsp;</span></div>");
                            if (regex.Match(input).Success)
                            {
                                input = regex.Replace(input, "{$:content.pagebreak}");
                                string[] separator = new string[] { "{$:content.pagebreak}" };
                                strArray = input.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                            }
                            else
                            {
                                strArray = new string[] { input };
                            }
                            for (int i = 0; i < strArray.Length; i++)
                            {
                                int num5;
                                string str10;
                                row["Content"] = strArray[i];
                                if (strArray.Length > 1)
                                {
                                    StringBuilder builder = new StringBuilder();
                                    builder.Append("<div class=\"page\"><span><strong>共" + strArray.Length + "页</strong></span>");
                                    for (int j = 0; j < strArray.Length; j++)
                                    {
                                        if (j == 0)
                                        {
                                            if (j == i)
                                            {
                                                builder.AppendFormat("<a class='current'>{0}</a>", j + 1);
                                            }
                                            else
                                            {
                                                builder.AppendFormat("<a href='{0}'>{1}</a>", row["ContentID"] + ".shtml", j + 1);
                                            }
                                        }
                                        else if (j > (strArray.Length - 3))
                                        {
                                            if (j == i)
                                            {
                                                builder.AppendFormat("<a class='current'>{0}</a>", j + 1);
                                            }
                                            else
                                            {
                                                builder.AppendFormat("<a href='{0}'>{1}</a>", string.Concat(new object[] { row["ContentID"], "_", j + 1, ".shtml" }), j + 1);
                                            }
                                        }
                                        else if ((j >= (i - 2)) && (j <= (i + 2)))
                                        {
                                            if (j == i)
                                            {
                                                builder.AppendFormat("<a class='current'>{0}</a>", j + 1);
                                            }
                                            else
                                            {
                                                builder.AppendFormat("<a href='{0}'>{1}</a>", string.Concat(new object[] { row["ContentID"], "_", j + 1, ".shtml" }), j + 1);
                                            }
                                        }
                                        else if ((j == (i - 3)) || (j == (i + 3)))
                                        {
                                            builder.AppendFormat("<a href='{0}'>...</a>", string.Concat(new object[] { row["ContentID"], "_", j + 1, ".shtml" }));
                                        }
                                    }
                                    if ((i != (strArray.Length - 1)) && (strArray.Length > 1))
                                    {
                                        builder.AppendFormat("<a href='{0}'>下一页</a>", string.Concat(new object[] { row["ContentID"], "_", i + 2, ".shtml" }));
                                        builder.AppendFormat("<a href='{0}'>尾页</a>", string.Concat(new object[] { row["ContentID"], "_", strArray.Length, ".shtml" }));
                                    }
                                    builder.Append("</div>");
                                    row["Content"] = row["Content"] + builder.ToString();
                                }
                                document.Variables.SetValue("content", row);
                                if (!string.IsNullOrEmpty(row["Keyword"].ToString()))
                                {
                                    string[] strArray3 = row["Keyword"].ToString().Split(" ".ToCharArray());
                                    StringBuilder builder2 = new StringBuilder();
                                    builder2.Append(" AND cc.ContentID in (SELECT DataID FROM dbo.SearchData WHERE Tag in (");
                                    num5 = 0;
                                    while (num5 < strArray3.Length)
                                    {
                                        string[] strArray4 = Utils.SplitString(SegmentHelper.GetKeyword(strArray3[num5]), " ");
                                        if (num5 != 0)
                                        {
                                            builder2.Append(",");
                                        }
                                        if (strArray4.Length > 1)
                                        {
                                            int index = 0;
                                            while (index < strArray4.Length)
                                            {
                                                if (index != 0)
                                                {
                                                    builder2.Append(",");
                                                }
                                                builder2.Append("'" + Utils.SqlStringFormat(strArray4[index], 1) + "' ");
                                                num5++;
                                            }
                                        }
                                        else
                                        {
                                            builder2.Append("'" + Utils.SqlStringFormat(strArray3[num5], 1) + "' ");
                                        }
                                        num5++;
                                    }
                                    builder2.Append("))");
                                    DataTable table2 = content.GetCmsContentDetailsByNodeID(nodeID, "TOP 10", builder2.ToString(), "");
                                    StringBuilder builder3 = new StringBuilder();
                                    builder3.AppendFormat("<ul>", new object[0]);
                                    foreach (DataRow row2 in table2.Rows)
                                    {
                                        builder3.AppendFormat("<li><a href=\"{0}\">\x00b7{1}</a></li>", GetItemUrlValue(Convert.ToInt32(row2["ContentID"]), Convert.ToInt32(row2["NodeID"])), row2["Title"]);
                                    }
                                    builder3.AppendFormat("</ul>", new object[0]);
                                    document.Variables.SetExpValue("content.keywordnews", builder3.ToString());
                                    StringBuilder builder4 = new StringBuilder();
                                    num5 = 0;
                                    while (num5 < strArray3.Length)
                                    {
                                        builder4.AppendFormat("<a href='{0}' target='_blank'>{1}</a>", "/aspx/Search.aspx?q=" + Utils.UrlEncode(strArray3[num5], "utf-8"), strArray3[num5]);
                                        num5++;
                                    }
                                    document.Variables.SetExpValue("content.keywordlinks", builder4.ToString());
                                }
                                if (!string.IsNullOrEmpty(row["Keyword"].ToString()))
                                {
                                    document.Variables.SetExpValue("content.commakeywords", ConvertKeywords(row["Keyword"].ToString()));
                                }
                                string str6 = node.GetModelByCache(content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID).ParentPath + "," + content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID;
                                StringBuilder builder5 = new StringBuilder();
                                string siteUrl = site.GetModelByCache(node.GetModelByCache(content.GetModelByCache(Convert.ToInt32(row["ContentID"])).NodeID).SiteID).SiteUrl;
                                for (num5 = 0; num5 < str6.Split(",".ToCharArray()).Length; num5++)
                                {
                                    KeRui.Model.CmsNode modelByCache;
                                    if (num5 != (str6.Split(",".ToCharArray()).Length - 1))
                                    {
                                        modelByCache = node.GetModelByCache(Convert.ToInt32(str6.Split(",".ToCharArray())[num5]));
                                        if (modelByCache.ShowOnMenu)
                                        {
                                            builder5.AppendFormat("<li><a href='{0}' class='c327CB6 '>{1}</a>>></li>", siteUrl + "/" + modelByCache.NodePath, modelByCache.NodeName);
                                        }
                                    }
                                    else
                                    {
                                        modelByCache = node.GetModelByCache(Convert.ToInt32(str6.Split(",".ToCharArray())[num5]));
                                        if (modelByCache.ShowOnMenu)
                                        {
                                            builder5.AppendFormat("<li><a href='{0}' class='c327CB6 '>{1}</a></li>", siteUrl + "/" + modelByCache.NodePath, modelByCache.NodeName);
                                        }
                                    }
                                }
                                document.Variables.SetExpValue("content.nav", builder5.ToString());
                                if (row["PrevID"].ToString() != "0")
                                {
                                    int contentID = Convert.ToInt32(row["PrevID"]);
                                    KeRui.Model.CmsContent content2 = content.GetModelByCache(contentID);
                                    if (content2 == null)
                                    {
                                        document.Variables.SetExpValue("content.pretitle", "没有文章了");
                                        document.Variables.SetExpValue("content.preurl", "#");
                                    }
                                    else
                                    {
                                        document.Variables.SetExpValue("content.pretitle", content2.Title);
                                        document.Variables.SetExpValue("content.preurl", GetItemUrlValue(content2.ContentID, content2.NodeID));
                                    }
                                }
                                if (row["NextID"].ToString() != "0")
                                {
                                    int num8 = Convert.ToInt32(row["NextID"]);
                                    KeRui.Model.CmsContent content3 = content.GetModelByCache(num8);
                                    if (content3 == null)
                                    {
                                        document.Variables.SetExpValue("content.nexttitle", "没有文章了");
                                        document.Variables.SetExpValue("content.nexturl", "#");
                                    }
                                    else
                                    {
                                        document.Variables.SetExpValue("content.nexttitle", content3.Title);
                                        document.Variables.SetExpValue("content.nexturl", GetItemUrlValue(content3.ContentID, content3.NodeID));
                                    }
                                }
                                ElementCollection<Template> childTemplatesByName = document.GetChildTemplatesByName("relativenews");
                                foreach (Template template in childTemplatesByName)
                                {
                                    DateTime time4;
                                    DataTable table3;
                                    string str8 = template.Attributes.GetValue("time");
                                    int top = Convert.ToInt32(template.Attributes.GetValue("num"));
                                    string dateRange = string.Empty;
                                    DateTime now = DateTime.Now;
                                    string str11 = str8;
                                    if (str11 != null)
                                    {
                                        if (!(str11 == "week"))
                                        {
                                            if (str11 == "month")
                                            {
                                                goto Label_0CE5;
                                            }
                                        }
                                        else
                                        {
                                            DateTime time2 = now.AddDays((double) (1 - Convert.ToInt32(now.DayOfWeek.ToString("d"))));
                                            DateTime time3 = time2.AddDays(6.0);
                                            dateRange = string.Concat(new object[] { " AND createtime between '", time2, "' and '", time3, "'" });
                                        }
                                    }
                                    goto Label_0D58;
                                Label_0CE5:
                                    time4 = now.AddDays((double) (1 - now.Day));
                                    DateTime time5 = time4.AddMonths(1).AddDays(-1.0);
                                    dateRange = string.Concat(new object[] { " AND createtime between '", time4, "' and '", time5, "'" });
                                Label_0D58:
                                    table3 = content.GetCmsContentRelativeNews(nodeID, template.Attributes.GetValue("type"), top, dateRange);
                                    template.Variables.SetValue("newsdata", table3);
                                    Tag childTagById = template.GetChildTagById("newslist");
                                    if ((childTagById != null) && (childTagById is ForEachTag))
                                    {
                                        childTagById.BeforeRender += new CancelEventHandler(Publish.Tag_BeforeRender);
                                    }
                                }
                                ResolveTag.ResolveForeach(document);
                                ResolveTag.ResolveTemplate(document);
                                if (i == 0)
                                {
                                    str10 = string.Concat(new object[] { node.GetModelByCache(nodeID).NodeDir, @"\", row["ContentID"], ".shtml" });
                                    GeneratePath(node.GetModelByCache(nodeID).NodeDir);
                                    document.RenderTo(str10, Encoding.GetEncoding("utf-8"));
                                }
                                else
                                {
                                    str10 = string.Concat(new object[] { node.GetModelByCache(nodeID).NodeDir, @"\", row["ContentID"], "_", i + 1, ".shtml" });
                                    GeneratePath(node.GetModelByCache(nodeID).NodeDir);
                                    document.RenderTo(str10, Encoding.GetEncoding("utf-8"));
                                }
                            }
                        }
                    }
                    num += table.Rows.Count;
                }
            }
            return num;
        }

        public int PublishContent(string nodeIDCollection, int type, string conditions, int current, int size)
        {
            int num = 0;
            int pageIndex = 1;
            int pageSize = size;
            KeRui.BLL.CmsContent content = new KeRui.BLL.CmsContent();
            KeRui.BLL.CmsNode node = new KeRui.BLL.CmsNode();
            foreach (string str in nodeIDCollection.Split(",".ToCharArray()))
            {
                int nodeID = Convert.ToInt16(str);
                if (node.GetModelByCache(nodeID).NodeType != 2)
                {
                    int count = content.GetCount("NodeID=" + str + " " + conditions + "  and IsDelete=0");
                    if (current < count)
                    {
                        pageIndex = 0;
                        pageIndex = (current / pageSize) + 1;
                    }
                    else if (current >= count)
                    {
                        current -= count;
                        goto Label_015B;
                    }
                    List<KeRui.Model.CmsContent> list = content.GetList("NodeID=" + str + " " + conditions + " and IsDelete=0", pageSize, pageIndex);
                    foreach (KeRui.Model.CmsContent content2 in list)
                    {
                        this.PublishContent(content2.ContentID);
                        num++;
                    }
                Label_015B:;
                }
            }
            return num;
        }

        public int PublishIndexPage(int siteID)
        {
            new Resolve().ResolvePage(PublicTypeEnum.PublicType.Index, siteID);
            return 1;
        }

        public void PublishInfoPages(int contentID)
        {
            KeRui.Model.CmsContent model = new KeRui.BLL.CmsContent().GetModel(contentID);
            KeRui.BLL.CmsNode node = new KeRui.BLL.CmsNode();
            this.PublishContent(contentID);
            this.PublishNodePage(model.NodeID);
            this.PublishIndexPage(node.GetModelByCache(model.NodeID).SiteID);
        }

        public int PublishNodePage(int[] nodeIDs)
        {
            if (nodeIDs.Length > 0)
            {
                foreach (int num in nodeIDs)
                {
                    Resolve resolve = new Resolve();
                    KeRui.Model.CmsNode modelByCache = new KeRui.BLL.CmsNode().GetModelByCache(num);
                    if (modelByCache.ParentID == 0)
                    {
                        resolve.ResolvePage(PublicTypeEnum.PublicType.Index, modelByCache.SiteID);
                    }
                    else
                    {
                        resolve.ResolvePage(PublicTypeEnum.PublicType.Node, num);
                    }
                }
            }
            return nodeIDs.Length;
        }

        public int PublishNodePage(int nodeID)
        {
            Resolve resolve = new Resolve();
            KeRui.Model.CmsNode modelByCache = new KeRui.BLL.CmsNode().GetModelByCache(nodeID);
            if (modelByCache.ParentID == 0)
            {
                resolve.ResolvePage(PublicTypeEnum.PublicType.Index, modelByCache.SiteID);
            }
            else
            {
                resolve.ResolvePage(PublicTypeEnum.PublicType.Node, nodeID);
            }
            return 1;
        }

        public string PublishNodePage(int nodeID, int PageIndex)
        {
            return Resolve.PublishNodePage(nodeID, PageIndex);
        }

        public string PublishNodePage(int nodeID, int PageIndex, string selectedValue)
        {
            return Resolve.PublishNodePage(nodeID, PageIndex, selectedValue);
        }

        public int PublishNodePageForCatcher(int[] nodeIDs)
        {
            if (nodeIDs.Length > 0)
            {
                foreach (int num in nodeIDs)
                {
                    Resolve resolve = new Resolve();
                    KeRui.Model.CmsNode modelByCache = new KeRui.BLL.CmsNode().GetModelByCache(num);
                    try
                    {
                        if (modelByCache.ParentID == 0)
                        {
                            resolve.ResolvePage(PublicTypeEnum.PublicType.Index, modelByCache.SiteID);
                        }
                        else
                        {
                            resolve.ResolvePage(PublicTypeEnum.PublicType.Node, num);
                        }
                    }
                    catch (Exception exception)
                    {
                        Utils.ErrorNote("Publish", string.Concat(new object[] { "nodeID：", num, "，详情：", exception.Message }));
                    }
                }
            }
            return nodeIDs.Length;
        }

        public string ResolveComment(string source, int contentID)
        {
            int num;
            KeRui.BLL.CmsContent content = new KeRui.BLL.CmsContent();
            KeRui.BLL.CmsNode node = new KeRui.BLL.CmsNode();
            KeRui.BLL.CmsSite site = new KeRui.BLL.CmsSite();
            TemplateDocument document = new TemplateDocument(source);
            string str = string.Format("{0},{1}", node.GetModelByCache(content.GetModel(Convert.ToInt32(contentID)).NodeID).ParentPath, content.GetModel(Convert.ToInt32(contentID)).NodeID);
            StringBuilder builder = new StringBuilder();
            string siteUrl = site.GetModelByCache(node.GetModelByCache(content.GetModel(Convert.ToInt32(contentID)).NodeID).SiteID).SiteUrl;
            builder.Append("<li>");
            for (num = 0; num < str.Split(",".ToCharArray()).Length; num++)
            {
                KeRui.Model.CmsNode modelByCache;
                if (num != (str.Split(",".ToCharArray()).Length - 1))
                {
                    modelByCache = node.GetModelByCache(Convert.ToInt32(str.Split(",".ToCharArray())[num]));
                    builder.AppendFormat("<a href='{0}' class='ContentPageLocation c327CB6'>{1}</a>&nbsp;>>&nbsp;", siteUrl + "/" + modelByCache.NodePath, modelByCache.NodeName);
                }
                else
                {
                    modelByCache = node.GetModelByCache(Convert.ToInt32(str.Split(",".ToCharArray())[num]));
                    builder.AppendFormat("<a href='{0}' class='ContentPageLocation c327CB6'>{1}</a>&nbsp;", siteUrl + "/" + modelByCache.NodePath, modelByCache.NodeName);
                }
            }
            builder.Append("</li>");
            document.Variables.SetExpValue("content.location", builder.ToString());
            string[] strArray = content.GetModelDetailsByContentID(Convert.ToInt32(contentID)).Tables[0].Rows[0]["keyword"].ToString().Split(" ".ToCharArray());
            StringBuilder builder2 = new StringBuilder();
            builder2.Append(" AND cc.ContentID in (SELECT DataID FROM dbo.SearchData WHERE Tag in (");
            for (num = 0; num < strArray.Length; num++)
            {
                string[] strArray2 = Utils.SplitString(SegmentHelper.GetKeyword(strArray[num]), " ");
                if (num != 0)
                {
                    builder2.Append(",");
                }
                if (strArray2.Length > 1)
                {
                    int index = 0;
                    while (index < strArray2.Length)
                    {
                        if (index != 0)
                        {
                            builder2.Append(",");
                        }
                        builder2.Append("'" + Utils.SqlStringFormat(strArray2[index], 1) + "' ");
                        num++;
                    }
                }
                else
                {
                    builder2.Append("'" + Utils.SqlStringFormat(strArray[num], 1) + "' ");
                }
            }
            builder2.Append("))");
            DataTable table = content.GetCmsContentDetailsByNodeID(content.GetModel(Convert.ToInt32(contentID)).NodeID, "TOP 10", builder2.ToString(), "");
            StringBuilder builder3 = new StringBuilder();
            builder3.AppendFormat("<ul>", new object[0]);
            foreach (DataRow row in table.Rows)
            {
                string str5 = (row["Title"].ToString().Length > 15) ? row["Title"].ToString().Substring(0, 14) : row["Title"].ToString();
                builder3.AppendFormat("<li><a href=\"{0}\" title='{2}'>\x00b7{1}</a></li>", GetItemUrlValue(Convert.ToInt32(row["ContentID"]), Convert.ToInt32(row["NodeID"])), str5, row["Title"]);
            }
            builder3.AppendFormat("</ul>", new object[0]);
            document.Variables.SetExpValue("content.keywordnews", builder3.ToString());
            StringBuilder builder4 = new StringBuilder();
            for (num = 0; num < strArray.Length; num++)
            {
                if (num < 3)
                {
                    builder4.AppendFormat("<a href='{0}' target='_blank'>{1}</a>", "/aspx/Search.aspx?q=" + Utils.UrlEncode(strArray[num], "utf-8"), strArray[num]);
                }
            }
            document.Variables.SetExpValue("content.keywordlinks", builder4.ToString());
            return document.GetRenderText();
        }

        private static void Tag_BeforeRender(object sender, CancelEventArgs e)
        {
            ForEachTag tag = (ForEachTag) sender;
            DataRowView view = (DataRowView) tag.Item.Value;
            if (view.Row.Table.Columns.Contains("NodeID"))
            {
                tag.Item.SetExpValue("url", GetItemUrlValue(Convert.ToInt32(view["ContentID"]), Convert.ToInt32(view["NodeID"])));
            }
            else
            {
                tag.Item.SetExpValue("url", GetItemUrlValue(Convert.ToInt32(view["ContentID"]), 0));
            }
            KeRui.BLL.CmsContent content = new KeRui.BLL.CmsContent();
            int contentID = Convert.ToInt32(view["PrevID"]);
            KeRui.Model.CmsContent modelByCache = content.GetModelByCache(contentID);
            if (modelByCache == null)
            {
                tag.Item.SetExpValue("pretitle", "没有文章了");
                tag.Item.SetExpValue("preurl", "#");
            }
            else
            {
                tag.Item.SetExpValue("pretitle", modelByCache.Title);
                tag.Item.SetExpValue("preurl", GetItemUrlValue(modelByCache.ContentID, modelByCache.NodeID));
            }
            int num2 = Convert.ToInt32(view["NextID"]);
            KeRui.Model.CmsContent content3 = content.GetModelByCache(num2);
            if (content3 == null)
            {
                tag.Item.SetExpValue("nexttitle", "没有文章了");
                tag.Item.SetExpValue("nexturl", "#");
            }
            else
            {
                tag.Item.SetExpValue("nexttitle", content3.Title);
                tag.Item.SetExpValue("nexturl", GetItemUrlValue(content3.ContentID, content3.NodeID));
            }
        }
    }
}

